<%@include file="header.jsp"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>

<!-- Show families -->
<%
	String familiesStyle = "";
	String message = "";
	if (request.getAttribute("familyList") == null) {
		familiesStyle = "style='display: none;'";
		message = "You don't have your own families. You can create this one.";
	} else
		familiesStyle = "style='display: block;'";
%>
<%=message%>

<h3>Your Families</h3>
<div>To edit participants of family, click to name of family you want to edit.</div>
<div class="family-div">
	<table class="family-table table" <%=familiesStyle%>>
		<tr>
			<td><b>Family</b></td>
			<td><b>Owner</b></td>
			<td><b>Action</b></td>
		</tr>
		<c:forEach var="family" items="${familyList}">
			<tr>
				<td><a href="families/${family.familyId}">${family.name}</a></td>
				<td>${family.username}</td>
				<td><button class="btn btn-mini btn-danger"
					onclick="confirmDelete('families/delete/${family.familyId}')">Delete</button></td>
			</tr>
		</c:forEach>
	</table>
</div>


<!-- From to add new family -->
<div class="alert alert-error"
	<%String errorStyle = "";
			if (request.getAttribute("errors") == null)
				errorStyle = "style='display: none;'";
			else
				errorStyle = "style='display: block;'";%>
	<%=errorStyle%>><%=request.getAttribute("errors")%></div>
<form id="create_family" action="families/add" class="form-signin">
	<h4>Create family</h4>
	<div class="control-group">
		<label class="control-label" for="name">Name</label>
		<div class="controls">
			<input id="name" class="required" name="name" path="name" type="text"
				placeholder="Name" />
		</div>
	</div>

	<button id="registerButton" class="btn btn-small btn-primary"
		type="submit">Create</button>
</form>
<script src="<spring:url value="/web/js/jquery-2.0.0.js" />"></script>
<script src="<spring:url value="/web/js/jquery.validate.js" />"></script>
<script src="<spring:url value="/web/js/bootstrap.js" />"></script>
<script src="<spring:url value="/web/js/script.js" />"></script>
<script src="<spring:url value="/web/js/invitationsManager.js" />"></script>
<script type="text/javascript">
	$(document).ready(function() {
		$("#create_family").validate();
	});
</script>


<%@include file="footer.jsp"%>